using UnityEngine;

namespace Gameplay.PVE.TurnBase
{
    public class SkillInitiative : SkillBase
    {
        protected override void StartMoveTo()
        {
            base.StartMoveTo();
            if (config.moveToFrame != 0)
            {
                if (config.actionNameBefore != null)
                {
                    unit.Play(config.actionNameBefore+"MoveTo",config.moveToSpeed);
                }
                else
                {
                    unit.Play("MoveTo",config.moveToSpeed);
                }

            }
            else
            {
                unit.Play("Walk");
            }
        }

        protected override void StartStorage()
        {
            var targetForward = targetUnit.Data.position - unit.Data.position;
            targetForward.y = 0;
            unit.Data.SetForward(targetForward);
            base.StartStorage();
            if (config.moveToFrame != 0)
            {
                
            }
            else
            {
                unit.Play("Idle");
            }
           
        }

        protected override void StartCast()
        {
            base.StartCast();
            if (config.moveToFrame != 0)
            {
                if (config.actionNameBefore != null)
                {
                    unit.Play(config.actionNameBefore+"MoveToAttack");
                }
                else
                {
                    unit.Play("MoveToAttack");
                }
            }
            else if (config.actionName == null)
            {
                unit.Play("Attack");
            }
            else
            {
                unit.Play("Skill");
            }
        }

        protected override void StartRecover()
        {
            base.StartRecover();
            if (config.moveToFrame != 0)
            {
                
            }
            else
            {
                unit.Play("Idle");
            }
        }

        protected override void StartMoveBack()
        {
            base.StartMoveBack();
            if (config.moveToFrame != 0)
            {
                if (config.actionNameBefore != null)
                {
                    unit.Play(config.actionNameBefore+"MoveBack",config.moveToSpeed);
                }
                else
                {
                    unit.Play("MoveBack",config.moveToSpeed);
                }
            }
            else
            {
                unit.Play("Walk");
            }
        }
        
        protected override void End()
        {
            base.End();
            unit.Play("Idle");
            RemoveUnitsFromCameraFocus();
        }
        
        
        public override void Update()
        {
            base.Update();
            /*if (unit.Data.isDead)
            {
                if (state != ESkillState.None)
                {
                    End();
                }
                return;
            }*/
        }
    }
}